<?php
//建造者模式builder
//产品本身
class Product {
    private $parts;
    public function __construct()
    {
        $this->parts = array();
    }
    public function add ($parts){
        return array_push($this->parts,$parts);
    }
}
// 建造者抽象类
abstract  class Builder {
    public abstract function builderPart1();
    public abstract function builderPart2();
    public abstract function getResult();
}

// 具体建造者
class ConcreteBuilder  extends Builder{
    private $product;
    public function __construct(){
        $this->product = new Product();
    }
    public function builderPart1()
    {
        // TODO: Implement builderPart1() method.
        $this->product->add("Part1");
    }
    public function builderPart2()
    {
        // TODO: Implement builderPart2() method.
        $this->product->add("Part2");
    }
    public function getResult()
    {
        // TODO: Implement getResult() method.
        return $this->product;
    }
}

//导演者

class Director{
    public function __construct(Builder $builder){
        $builder->builderPart1();
        $builder->builderPart2();
    }
}

// client
$buidler = new ConcreteBuilder();
$director = new Director($buidler);
$product = $buidler->getResult();
var_dump($product);






